using System;
using System.Collections.Generic;
using Truesight.Api.Meta.Attrs;
using Truesight.Api.Meta.Collections;
using Truesight.Api.Meta.Core;
using Truesight.Api.Meta.Generics;

namespace Truesight.Api.Dynamic.Core
{
    public interface ICallSite : ICanBeGeneric<ICallSite>, IHaveAttrs
    {
        String Name { get; set; }

        IParams Params { get; }
        IParam Return { get; set; } // can be set to null
        Type Signature { get; set; }

        bool IsStatic { get; set; }
        // Target (not present in ICallSite)
        IBoundCallSite Bind(Object target);
        // Unbind (not present in ICallSite)

        Object Invoke(Object target, params Object[] args);
        Object Invoke(Object target, IEnumerable<Object> args);
        // 1. callsites cannot be abstract - tho their implementations for "target" can be
        // 2. sometimes we ain't need to call Derive even if the callsite is a surrogate generic
        // Microsoft.CSharp is so awesome that it'll infer typeargs correctly if it can be done

        // Original (not present in ICallSite)
        // shitloads of various casts (jeez...)
    }

    // here we need to add shitloads of different ICallSite<...> classes for Action<...> and Func<...>
    // and all of those need personal bound/unbound signatures as well, omg...
    // also those need personal implementations of ICanBeGeneric<ICallSite<...>>

    // Implementation tips:
    // 1. No need to implement ICallSite_Func<...> and ICallSite_Action<...>:
    //    we can use F#'s approach and implement a single ICallSite<...> class
    //    with the last type argument being Unit (see Unit.cs)
    // 2. See the picture below (can you guess what is displayed there?)

    /*
    ?????????+???$+??Z?+??????+?++=?+?++?+??????~??+??????=?????????????????????????
    ?????????+???7+??$?+?=+?????????+?+??++++???+~?+??????????????????~?????????~???
    ?????????????????$I++:,.......:.~:=+??++??I??I??????????????????++?++?????++????
    ??????????+???$+=:,....  .............~~+~??:++?I???+??????+???????????~??+?????
    ??????????=???~,:................     ...::????+???????????????????+???????I:I??
    ?????????++=~,..:,,:,~:~~~:,,~:,... . ....~:??+???????????????????????????????+I
    ?????????I,~~,,:,:,:,::~~:~~:~~:::....   ..,.:??????????????????????I+~+???+????
    ????????+~:::,:.:,:~::~:~:+++=~:::::..   ..,::=???????????+???????????I?+?????+?
    ??????I=+=~~::,:,:~:~:=~I=~+==?:==:~,~.... .::~=~?????????+???????????????I+??=I
    ?????+?+++~=~::::::=~~~:~==~+~~+~~=~:~.,:  ..:::~~??????????????????+?I?I?+???+I
    ?????++??I:~=+~~~~=~~=~~,:+~=~=+~?:+=~::~.... .:::~+?????????????+??+????+?I??=?
    ?????+?I???+++++=+=~====~~+~:===+~~::~:::,... ..:.~~+?????????????????+???+?+???
    ???+?+I????+???+????~~~~=~==~+~==?~+~+:~~~........,::=???????????+?=?=+????????+
    $$$77II????+??+++?+++~++=~=~~=+:=~=+~+:::::,.....,,:~~?II???I??II???????II?$II??
    ????$I??+?II?+???+?+??==~+~?+==:==+~~:~~==+,,,,,..:,,~~+???????????????????+?+??
    ????$Z$$I77$I+??++?+?+++=+==++~+=+~=+=~=~?:~::,.::,:,~:=?????????????????+???+++
    ????$8OZ$777III+?II?++++++~+::=+==+===~~=?~=+::~:::,:~:~???????????=????????=I++
    ????7N8Z$ZI77$+?I+?I???+?++=+=??+~~=~+~+==++==~=~::::~::=???????????????????????
    ????I8DDZZZZ77$???+???+?++++++++==+++~=??==+~+=+?+~:~~~:::,:::.,~.::::~~~~~:=~~=
    ?????$O8O$Z$7$$777?+II+?++?+++++~++?+++?:=+?+++~=+~?=:~::,..........,,:....,.,~:
    ??????8OOZOZ$$7$???III7+I?++??+?+++++=+++++++~=+??+=++=~~~.~,:.,...,.,.:,..,....
    ??????I8OOOZZ$$7II$?+I?I+??=II?++++++++++++++++?===~=::::~:::~.,,:.::.,.:~,..,..
    ???????$$8OO8ZZ$$$?I$$7+?7I+?+?7?+?++??I=+?+++++~~:,:?~~~+:~~~~:=~~:~~~~~~~:~::~
    ????????OD8OO$OZZ77?77$I??II$???$?I7I+7???++I+:::,:~~+~=:::===~~~~~+~~~+:~==~?+=
    ?????+??$DD88Z88O8O?$I????$7?I??+7II7$IIIZ?~?~~+:=~=?~~,::~:+??=+?=?+?~?+~+I=:?+
    ????????I7O8DOD8$ZZZ$$$$$I??7777?I$7??I?+~+=:=+++=?I+~,,:~~++??????I?++?I??+?+=+
    ??I?????7???78$888ZZ$I?I?$7II?7II?Z7$7?+=+:~~+=+$7I,,,:~+I==~????++I??????+I++?+
    I$7I?+??O88Z$ZZ$$8O$ON8$I?+I7??I$7?7?~~+?=+==?I?=:~:::~?I?+=+7??????????????????
    ??7$7III7Z7ZO8OZZZ8O$?=~~?I?I$I?7O??+=??++=?7I=+:::~=?I$I??+++I??I???I??????????
    ??Z$$7?+?Z7$D$OOOOOOZZ$+~++7??777++++++?++?7+?=+:+==77$~~:.=?I???I???++???+?+?+?
    I$$7Z?$Z7$77DZZZ$ZO$Z777+++++ZZ?+++==++???=+?=::++?I$I~,..:??+++??+?++=++?~??+??
    Z$ZI?I7$Z$Z$O88ZZZZZ$Z$$I+~+$$?~++==++++:?~+=~~+?I=:.,..~~+?+?++??I??+=++??+??++
    ZZZZ7OZOOOO$O$I$ZOOO$$Z$++=?+++~+==:==~=~=~~=+7?++:,~~:~=+??++???+?~~=?+$$OD8888
    Z$ZOZDZ8$DZOZZ$Z$Z$$OOZ$+??=+==+~~:::=:::~==?I?~+:~~+=?I?+?+7I$$Z888DOD8888D8DD8
    ZZ$OZO$ODZ8OD$Z7$$OZZ$$$+???+~+~=~~=++++=?++==++=++?+$I:,,~Z88888888O888DOOOD888
    ZD8$D88ODO88888O$O$ZOO$I+=+++++=:+++++++?~~=,=+=+?77?:..,:=Z88DDDDD8D888888DDD88
    $Z8ZZD8Z8D8D8D888D$$$O7?+++~?I=~+?=++~+~~+==:~~~+?+~=+:~+?I7D8DDDDDDD8D8DDDN8DNN
    O8OD88DD8D8ODDD8MM$Z$$?+++++=?==+?===~+++~~==:~=+~~:=~=??+??MODDND8DDDDD8DDN888D
    $OD888ODD8888D8DMMZ$ZI7I++++~+?++++?+=?~==?=+~=,~=++III?~?$ZNDDDDDDDDDD8DDDDDD8D
    Z88O8D88DDD8DDOMNMM$ZZ7I?+=+==+=+=+++?++=+~++~+=+==+II7$7I$NDND8DD88DDNNDDN888ZZ
    ZO8DO888D888NDMM88MN$7I$?+=~+=++++==+=++?+=+???+?=+7$7I77?ODNDDND8NDN8N88DDO7$7$
    DD8OD8DDD8MDMMMMMDNDM$7I??+=??+=+?++++?++++++++?++IZ$$$ZO$8NDMDD8DNDNNDNO77Z7$$$
    ODD8DNMMMMMNMNMMMMNMN$7?++++++=+?=++++++++++~=+?I+7Z7Z777ZMNDDM8DMND88Z7Z$Z$ZZZZ
    D8MMNMMNNMM888MMMMNMD?$?+??=++=++++++++?++????+I?$ZZ7I$$I$8ODDM8ND8O7$$ZOOOOO8DO
    DDNDMMMMMDNDMMMMNNMNDI?++=++++++=+++?=+?+I??I???7Z77$Z777NMNDMNO$$7OOZOOONNOMND8
    D8D88888DDMNNNMMMMNMZI??++~++=?++=+++?+?I7$?+?I$ZO$O7878MD8O$ZZO88O8ODNM8NDDMNMM
    D88888O888D8DDNMMDDD7??++?+++++=?+?++?I+?I?+?7$8OOZ$O8OO8O88ODNND8M8DMD8NDON8888
    88DD88DNDNDDMD8DDD8Z?++?++I+?+?+++?=???I7$7$?8DD8MD888DNNDMD8MDD8MN8DN8ND88OONDN
    N88DMNMDN8NMMNMMNNZ++?++++??7?+II??+??I+7?IODMM8NDNDDMNN8N8MDD8NN8NNNDD888D8ODD8
    N8NNDMMMDNMMND8888??++++I??+???I++?+I??I$$8DDD8MDNNM8DND8D88MDND8ONODN8D8DODOOOO
    N8MNDDDM88ND8NDMOII=?+??I???I+?++?++?777$DDMNMNMN8NDD8MD8NDNODD8NODDON8OZNOODOOO
     * */
}